﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <link href="<?php echo base_url()?>common/css/public.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="<?php echo base_url()?>common/kindeditor/themes/default/default.css" />
    <script src="<?php echo base_url()?>common/kindeditor/kindeditor.js"></script>
    <script src="<?php echo base_url()?>common/kindeditor/lang/zh_CN.js"></script>
    <script>
        KindEditor.ready(function (K) {
            var editor = K.editor({
                allowFileManager: true
            });
            K('#insertfile').click(function () {
                editor.loadPlugin('insertfile', function () {
                    editor.plugin.fileDialog({
                        fileUrl: K('#url').val(),
                        clickFn: function (url, title) {
                            K('#url').val(url);
                            editor.hideDialog();
                        }
                    });
                });
            });
        });
    </script>

    <link href="<?php echo base_url()?>common/uploadify/uploadify.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="<?php echo base_url()?>common/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url()?>common/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url()?>common/layer/layer.js"></script>

</head>
<body>
    <h1>Uploadify Demo</h1>
    <style type="text/css">
        .file_btn {
            line-height: 20px;
            text-align: center;
            border: 1px solid #7a7979;
        }
    </style>
    <form>

        <input id="file_upload" name="file_upload" type="file" multiple="true">
        <a href="javascript:$('#file_upload').uploadify('upload','*')">上传</a>
        <input id="down_url" name="down_url" type="text" value="" />
        <input id="down_name" name="down_name" type="hidden" value="" />

    </form>
    <script type="text/javascript">
<?php $timestamp = time();?>
        $(function () {
            $('#file_upload').uploadify({
                'formData': {
                    'timestamp': '<?php echo $timestamp;?>',
                    'token': '<?php echo md5('unique_salt' . $timestamp);?>',

                },
                'swf': '<?php echo base_url()?>common/uploadify/uploadify.swf',
                'uploader': '<?php echo base_url()?>common/kindeditor/php/upload_json_file.php?dir=file',
                'buttonText': '选择',
                'auto': false,
                'multi': false,
                'height': '20',
                'width': '80',
                'buttonClass': 'file_btn',
                'onUploadSuccess': function (file, data, response) {
                    var jsonData = $.parseJSON(data);
                    if (jsonData.error == 0) {
                        $("#down_url").val(jsonData.url);
                        $("#down_name").val(file.name);
                    } else {
                        layer.msg(jsonData.message, { icon: 0 });
                    }
                }
            });
        });
    </script>







    <br />
    <input type="text" id="url" value="" /> <input type="button" id="insertfile" value="选择文件" />
</body>
</html>
